<ui:composition template="mainTemplate.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets" 
                >
    <ui:define name="title">Profile</ui:define>

    <ui:define name="content">

        <h:panelGrid columns="2">
            Firstname
            <h:outputText value="#{profileController.user.firstname}"/>

            Lastname
            <h:outputText value="#{profileController.user.lastname}"/>

            Username
            <h:outputText value="#{profileController.user.username}"/>

            Email
            <h:outputText value="#{profileController.user.email}"/>

            Role
            <h:outputText value="#{profileController.user.role.name}"/>
        </h:panelGrid>

        <h:form rendered="#{profileController.shouldShowPromote}">
            <h:commandButton action="#{profileController.promote}"
                             rendered="#{!profileController.isAdmin}"
                             value="Promote"/>
            <h:commandButton action="#{profileController.demote}"
                             rendered="#{profileController.isAdmin}"
                             value="Demote"/>
        </h:form>
        <br/>
        <h3>Download history</h3>
        <h:dataTable value="#{profileController.downloads}" var="item"
                     bgcolor="#fafafa" border="0" cellpadding="5" cellspacing="3"
                     first="0" width="50%" frame="border" styleClass="dataTable">
            <h:column>
                <f:facet name="header">
                    File
                </f:facet>
                <h:link outcome="pretty:fileinfo">
                    #{item.filedescription.name}
                    <f:param name="id" value="#{item.filedescription.id}"/>
                </h:link>
            </h:column>

            <h:column>
                <f:facet name="header">
                    Timestamp
                </f:facet>
                #{item.timestamp}
            </h:column>
        </h:dataTable>
    </ui:define>
</ui:composition>